import http from "utils/http.js"
const music = {
	innerAudioContext: null,
	play() {
		console.log("8788999");
		if (!this.innerAudioContext) {
			this.innerAudioContext = uni.createInnerAudioContext();
			http({
				url: "api/common/get_general",
			}).then(res => {
				if (res.data.code == 1) {
					if(res.data.data.bg_music_url){
						this.innerAudioContext.src = res.data.data.bg_music_url
					}else{
						this.innerAudioContext.src = 'https://mhadmin.km66.cn/music.mp3'
					}
					this.innerAudioContext.play();
				}
			}).catch(err => {});
		} else if (this.innerAudioContext.paused) {
			this.innerAudioContext.play();
		}
	},
	pause(){
		if (this.innerAudioContext) {
			this.innerAudioContext.pause();
		}
	},
	stop() {
		if (this.innerAudioContext) {
			this.innerAudioContext.stop();
		}
	},
	destroy() {
		if (this.innerAudioContext) {
			this.innerAudioContext.destroy();
			this.innerAudioContext = null;
		}
	}
}

export default music;